package com.kaifamiao.month04.day21.homework;

public class Triangle extends Shape{

    private double firstEdge ;
    private double secondEdge ;
    private double thirdEdge ;

    private final static String type = "三角形";



    public Triangle(){
        super(type);
    }

    public Triangle(double first , double second , double third ){
        super(type);
        isLegal(first, second, third);
        this.firstEdge = first;
        this.secondEdge = second;
        this.thirdEdge = third;
    }

    private void isLegal(double first, double second, double third) {
        if (!(first + second > third && first + third > second && second + third > first)) {
            throw new WrongSideLengthOfTriangleException("错误的边长：" + first + "," + second + "," + third);
        }
    }

    @Override
    public void calculate() {
        super.area = (double) 1 / 4 * Math.sqrt((this.firstEdge + this.secondEdge + this.thirdEdge) *
                (this.firstEdge + this.secondEdge - this.thirdEdge) * (this.firstEdge + this.thirdEdge - this.secondEdge) *
                (this.secondEdge + this.thirdEdge - this.firstEdge));;
//        System.out.println("当前的面积" + super.getType() + "面积是" + super.area);
    }


    @Override
    public void show() {
        System.out.println(type + "的边长：" + this.firstEdge + "," + this.thirdEdge + "," + this.secondEdge);
        super.show();
    }

    private static class WrongSideLengthOfTriangleException extends RuntimeException {
        public WrongSideLengthOfTriangleException(String message) {
            super(message);
        }
    }

}
